<!--

 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="pptist-editor">
    <EditorHeader class="layout-header" />
    <div class="layout-content">
      <!-- 左侧 -->
      <Thumbnails class="layout-content-left" />
      <div class="layout-content-center">
        <!-- 顶部图标 -->
        <!-- <CanvasTool class="center-top" /> -->
        <!-- 中间画布 -->
        <Canvas class="center-body" :style="{ height: `calc(100% - ${remarkHeight + 40}px)` }" />
        <!-- <Remark
          class="center-bottom" 
          v-model:height="remarkHeight" 
          :style="{ height: `${remarkHeight}px` }"
        /> -->
        <el-row style="min-width: 1000px;">
          <el-col :span="24">
            <div class="page-number" style="text-align: center; width: 100%; height: 100px; line-height: 100px;">
              场景{{ slideIndex + 1 }}: 场景 0000000{{ slideIndex + 1 }}</div>
          </el-col>
        </el-row>
      </div>
      <Toolbar class="layout-content-right" />
    </div>
  </div>

  <SelectPanel v-if="showSelectPanel" />

  <Modal :visible="!!dialogForExport" :footer="null" centered :closable="false" :width="680" destroyOnClose
    @cancel="closeExportDialog()">
    <ExportDialog />
  </Modal>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { storeToRefs } from 'pinia'
import { useMainStore, useSlidesStore, useSnapshotStore } from '@/store'
import useGlobalHotkey from '@/hooks/useGlobalHotkey'
import usePasteEvent from '@/hooks/usePasteEvent'
const slidesStore = useSlidesStore();
const { slides, slideIndex } = storeToRefs(slidesStore);
import EditorHeader from './EditorHeader/index.vue'
import Canvas from './Canvas/index.vue'
import CanvasTool from './CanvasTool/index.vue'
import Thumbnails from './Thumbnails/index.vue'
import Toolbar from './Toolbar/index.vue'
import Remark from './Remark/index.vue'
const snapshotStore = useSnapshotStore();
import ExportDialog from './ExportDialog/index.vue'
import SelectPanel from './SelectPanel.vue'
import { Modal } from 'ant-design-vue'
import { getScene } from "../../api/facility/index";
import { useRoute } from "vue-router";
import { log } from '@antv/g2plot/lib/utils'
import { deleteDiscardedDB } from "@/utils/database";
import { LOCALSTORAGE_KEY_DISCARDED_DB } from "@/configs/storage";
import useSlideHandler from '@/hooks/useSlideHandler'
const { resetSlides } = useSlideHandler();
const mainStore = useMainStore()
const { dialogForExport, showSelectPanel } = storeToRefs(mainStore)
const closeExportDialog = () => mainStore.setDialogForExport('')
const { databaseId } = storeToRefs(mainStore);
const remarkHeight = ref(40)

useGlobalHotkey()
usePasteEvent()
slidesStore.$reset()
// import { getScene } from "../api/facility/index.ts";
const route = useRoute();
getScene(route.query.id?route.query.id:localStorage.getItem('val')).then(({ data }) => {
  let a = useMainStore()
  let b = useSlidesStore()
  resetSlides()
  // let list = data.data.map((v: any) => JSON.parse(v.content))
  // b.slides.forEach((v: any) => {
  //   b.deleteSlide(v.id)

  // })

  let list = data.data.forEach((v: any) => {

    // console.log(JSON.parse(JSON.parse(v.content)));


    b.addSlide(JSON.parse(JSON.parse(v.content)))
    // console.log(b.slides);

    // console.log("id", b.slides[0].id);



  });
  if (data.data.length == 0) {
    b.addSlide({
      id: 'test-slide-1',
      elements: [
      ],
      background: {
        type: 'solid',
        color: '#FFFFFFFF',
      },
      sceneSize: "",
      sceneTime: '10',
      sceneName: ''
    },)
  }

  b.slides[0].id = b.slides[0].id + "$$$"
  b.deleteSlide(b.slides[0].id)

  // slides


})

onMounted(async () => {
  await deleteDiscardedDB();
  snapshotStore.initSnapshotDatabase();
  mainStore.setAvailableFonts();
})
window.addEventListener("unload", () => {
  const discardedDB = localStorage.getItem(LOCALSTORAGE_KEY_DISCARDED_DB);
  const discardedDBList: string[] = discardedDB ? JSON.parse(discardedDB) : [];

  discardedDBList.push(databaseId.value);

  const newDiscardedDB = JSON.stringify(discardedDBList);
  localStorage.setItem(LOCALSTORAGE_KEY_DISCARDED_DB, newDiscardedDB);
});



















</script>

<style lang="scss" scoped>
.pptist-editor {
  height: 100%;
}

.layout-header {
  height: 50px;
}

.layout-content {
  height: calc(100% - 40px);
  display: flex;
}

.layout-content-left {
  width: 260px !important;
  height: 100%;
  // flex-shrink: 0;
}

.layout-content-center {
  width: calc(100% - 160px - 260px);

  .center-top {
    height: 40px;
  }
}

.layout-content-right {
  width: 20%;
  height: 100%;
}
</style>